fn main() {
    println!("------------------------------");
    test01_match();
    println!("------------------------------");
    test02_match_multiline();
    println!("------------------------------");
    test03_match_enum_inner();
    println!("------------------------------");
    test04_match_option();
    println!("------------------------------");
    test05_match_other();
    println!("------------------------------");
    test06_match_nouse();
    println!("------------------------------");
    test07_match_nocode();
    println!("------------------------------");
}

//enum Coin {
//    Penny,
//    Nickel,
//    Dime,
//    Quarter,
//}

//fn value_in_cents(coin: Coin) -> u8 {
//    match coin {
//        Coin::Penny => 1,
//        Coin::Nickel => 5,
//        Coin::Dime => 10,
//        Coin::Quarter => 25,
//    }
//}

fn test01_match() {
    let coin = Coin::Nickel;
    let value = value_in_cents(coin);
    println!("value is {value}");
}

//fn value_in_cents(coin: Coin) -> u8 {
//    match coin {
//        Coin::Penny => {
//            println!("Lucky penny!");
//            1
//        }
//        Coin::Nickel => 5,
//        Coin::Dime => 10,
//        Coin::Quarter => 25,
//    }
//}

fn test02_match_multiline() {
    let coin = Coin::Penny;
    let value = value_in_cents(coin);
    println!("value is {value}");
}

#[derive(Debug)] // 这样可以立刻看到州的名称
enum UsState {
    Alabama,
    Alaska,
    // --snip--
}

enum Coin {
    Penny,
    Nickel,
    Dime,
    Quarter(UsState),
}

fn value_in_cents(coin: Coin) -> u8 {
    match coin {
        Coin::Penny => 1,
        Coin::Nickel => 5,
        Coin::Dime => 10,
        Coin::Quarter(state) => {
            println!("State quarter from {state:?}!");
            25
        }
    }
}

fn test03_match_enum_inner() {
    let state = UsState::Alaska;
    let coin = Coin::Quarter(state);
    let value = value_in_cents(coin);
    println!("value is {value}");
}

fn plus_one(x: Option<i32>) -> Option<i32> {
    match x {
        None => None,
        Some(i) => Some(i + 1),
    }
}
fn test04_match_option() {
    let five = Some(5);
    let six = plus_one(five);
    let none = plus_one(None);

    println!("{five:?}");
    println!("{six:?}");
    println!("{none:?}");
}

fn add_fancy_hat() {
    println!("add fancy hat");
}
fn remove_fancy_hat() {
    println!("remove fancy hat");
}
fn move_player(num_spaces: u8) {
    println!("move player {num_spaces} spaces");
}

fn test05_match_other() {
    let dice_roll = 9;
    match dice_roll {
        3 => add_fancy_hat(),
        7 => remove_fancy_hat(),
        other => move_player(other),
    }
}

fn reroll() {
    println!("reroll");
}

fn test06_match_nouse() {
    let dice_roll = 9;
    match dice_roll {
        3 => add_fancy_hat(),
        7 => remove_fancy_hat(),
        _ => reroll(),
    }
}

fn test07_match_nocode() {
    let dice_roll = 9;
    match dice_roll {
        3 => add_fancy_hat(),
        7 => remove_fancy_hat(),
        _ => (),
    }
}
